from pygame import *
from pygame.locals import *
import math

class Bullet:
     def __init__(self, startx, starty, goalx, goaly):
          self.posx = startx
          self.posy = starty
          self.width = 8
          self.height = 22
          self.targetx = goalx
          self.targety = goaly
          self.speed = 30
          self.overloadx = 0
          self.overloady = 0
          self.isplayer = False
          self.dmg = 50

     
     def move(self):
          richtungx = self.targetx - self.posx
          richtungy = self.targety - self.posy
          laengealt = math.sqrt((richtungx * richtungx) + (richtungy * richtungy))
          if(laengealt > self.speed):
               richtungx = richtungx * self.speed / laengealt
               richtungy = richtungy * self.speed / laengealt
               self.posx = self.posx + int(richtungx)
               self.posy = self.posy + int(richtungy)
               
               if(self.overloadx > 1):
                    self.posx += 1
                    self.targetx += 1
                    self.overloadx -= 1               
               if(self.overloady > 1):
                    self.posy += 1
                    self.targety += 1
                    self.overloady -= 1               
               if(self.overloadx < -1):
                    self.posx -= 1
                    self.targetx -= 1
                    self.overloadx += 1                    
               if(self.overloady < -1):
                    self.posy -= 1
                    self.targety -= 1
                    self.overloady += 1                    
               self.overloadx += richtungx - int(richtungx)
               self.overloady += richtungy - int(richtungy)

          else:
               self.posx = self.targetx
               self.posy = self.targety
